# -*- coding: utf-8 -*-
#
# File: EventFolderView.py
#
# Copyright (c) 2009 by ngi644.net
# Generator: ArchGenXML Version 2.4.1
#            http://plone.org/products/archgenxml
#
# GNU General Public License (GPL)
#

__author__ = """Takashi NAGAI <nagai@ngi644.net>"""
__docformat__ = 'plaintext'

##code-section module-header #fill in your manual code here
##/code-section module-header

from zope import interface
from zope import component
from Products.CMFPlone import utils
from Products.Five import BrowserView
from zope.interface import implements
from Products.tfcaEvent.interfaces.IEventFolder import IEventFolder
from Products.CMFDynamicViewFTI.browserdefault import BrowserDefaultMixin

from Acquisition import aq_inner
from Products.CMFCore.utils import getToolByName
from DateTime import DateTime
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from Products.CMFPlone import PloneMessageFactory as _

import calendar


YEAR_LIST=[(str(x),str(x)) for x in range(2008,2020+1)]
MONTH_LIST=[(str(x),str(x)) for x in range(1,12+1)]

class EventFolderView(BrowserView):
    """
    """
    implements(IEventFolder)

    ##code-section class-header_EventFolderView #fill in your manual code here
    ##/code-section class-header_EventFolderView

    def getNowDateTime(self):
        return DateTime()

    def getEventList(self, vYear=0, vMonth=0):
        #import pdb;pdb.set_trace()
        context = self.context
        now = DateTime()
        now_year = now.year()
        now_month = now.month()
        now_day = now.day()
        if vYear != 0:
            chk_year = int(vYear)
        else:
            chk_year = now_year
        if vMonth != 0:
            chk_month = int(vMonth)
        else:
            chk_month = now_month
        base_query = {}
        base_query['sort_on'] = 'start'
        base_query['sort_order'] = 'ascending'
        base_query['portal_type'] = ('tfcaTrainingEvent', 'tfcaCall4Vlounteer')
        st_data = DateTime('%s/%.2d/01' % (chk_year,chk_month))
        ed_day = calendar.monthrange(chk_year, chk_month)[1]
        ed_data = DateTime('%s/%.2d/%.2d 23:59' % (chk_year,chk_month,ed_day))
        base_query['start'] = {'query':[ed_data], 'range':'max'}
        base_query['end'] = {'query':[st_data,], 'range':'min'}          
        portal_catalog = getToolByName(self, 'portal_catalog')
        ev_results = portal_catalog(base_query)
        return ev_results

    def getMonthList(self):
        return MONTH_LIST
    
    def getYearList(self):
        return YEAR_LIST
    


##code-section module-footer #fill in your manual code here
##/code-section module-footer


